#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_netcamera.h"

#include <QtMqtt/QMqttClient>
#include <QtMqtt/QMqttSubscription>
#include <QtMqtt/QMqttPublishProperties>
#include <QGridLayout>
#include <QProgressBar>
#include <QTimer>
#include "camera.h"
#include "task.h"
#include "picture.h"
#include "newtaskedit.h"

class NetCamera : public QMainWindow
{
    Q_OBJECT

public:
    NetCamera(QWidget *parent = Q_NULLPTR);

private:
    Ui::NetCameraClass ui;
    QMqttClient* m_client;
    QMqttSubscription* disc_sub, * will_sub;
    QGridLayout* layout_cam, * layout_pic;
    QWidget* sc_widget, * sp_widget;
    QString active_sn = "";
    QProgressBar* prog_bar;
    QLabel* pic_indicator;
    QTimer* timer;
    QPushButton* btn_new_task;
    NewTaskEdit* task_edit;
    QImage cur_img;
    void mqtt_offline_stat();
    void mqtt_online_stat();
    void dev_offline_stat();
    void dev_online_stat();
    void set_busy(void);
    void set_idle(void);
    Camera* find_cam(QString sn);
    void delete_all_task(void);
    void delete_all_picture(void);
    void sn_reboot_resp(QJsonObject jb);
    void sn_format_resp(QJsonObject jb);
    void sn_snap_resp(QJsonObject jb);
    void sn_taskset_resp(QJsonObject jb);
    void sn_taskget_resp(QJsonObject jb);
    void sn_taskdel_resp(QJsonObject jb);

    virtual void resizeEvent(QResizeEvent* event);

private slots:
    void timer_timeout();
    void btn_test_clicked();
    void btn_connect_clicked();
    void btn_discovery_clicked();
    void btn_snap_clicked();
    void btn_save_clicked();
    void btn_reboot_clicked();
    void btn_format_clicked();
    void btn_list_clicked();
    void btn_refresh_clicked();
    void mqtt_connected();
    void mqtt_disconnected();
    void disc_msg_rcv(QMqttMessage msg);
    void will_msg_rcv(QMqttMessage msg);
    void sn_resp_msg_rcv(QMqttMessage msg);
    void sn_event_msg_rcv(QMqttMessage msg);
    void cam_activate(bool activate, QString sn);
    void task_del(int time);
    void btn_new_task_clicked();
    void edit_ok_clicked(int time);
    void edit_cancel_clicked();
    void show_another_pic(Picture* pic);
};
